from django.db import models

site_choice = (
    # 站点信息
    ('US', '美国'), ('UK', '英国'), ('ES', '西班牙'), ('DE', '德国'),
    ('CA', '加拿大'), ('FR', '法国'), ('IT', '意大利'), ('JP', '日本'),
    ('AE', '阿联酋'), ('NL', '荷兰'), ('AU', '澳大利亚'), ('MX', '墨西哥'),
    ('SA', '沙特阿拉伯'), ('SE', '瑞典'), ('IN', '印度'), ('AU', '澳大利亚'),)


class AmazonFbaReimbursementStatistics(models.Model):
    # AMZ-FBA赔偿统计
    id = models.AutoField('id', primary_key=True)
    userid = models.IntegerField('用户id', blank=False, null=False)
    shop_name = models.CharField('店铺', max_length=32, blank=True, null=True)
    sku = models.CharField('店铺SKU', max_length=255, blank=True, null=True)
    fnsku = models.CharField('FNSKU', max_length=32, blank=True, null=True)
    inventory_misplaced = models.IntegerField('误放库存', blank=True, null=True)
    inventory_damaged = models.IntegerField('残损库存', blank=True, null=True)
    inventory_found = models.IntegerField('已找到库存', blank=True, null=True)
    inventory_reimbursed_total = models.IntegerField('总丢失库存', blank=True, null=True)
    reimbursed_cash_quantity = models.IntegerField('现金赔偿', blank=True, null=True)
    reimbursed_inventory_quantity = models.IntegerField('库存赔偿', blank=True, null=True)
    reimbursed_total_quantity = models.IntegerField('总已赔偿', blank=True, null=True)
    reimbursed_need = models.IntegerField('仍需赔偿', blank=True, null=True)
    remark = models.CharField('操作备注', max_length=255, blank=True, null=True)
    refresh_time = models.DateTimeField('刷新时间', blank=True, null=True)
    case_id = models.CharField('Case Id', max_length=30, blank=True, null=True)
    update_case_id_datetime = models.DateTimeField('Case id更新时间', blank=True, null=True)
    display = models.IntegerField('是否显示,默认不显示', default=0)

    class Meta:
        verbose_name = u'AMZ-FBA赔偿统计'
        verbose_name_plural = verbose_name
        db_table = 't_amazon_fba_reimbursement_statistics'

    def __unicode__(self):
        return u'%s' % self.id


class AmazonRefundStatisticsDetail(models.Model):
    # AMZ-索赔统计-明细
    refund_type_selection = ((1, '库存丢失或损坏'), (3, '未经卖家允许亚马逊销毁的商品'), (4, '入仓比发货数少'),
                             (5, '赔偿金额不符合商品实际价值'), (7, '退款金额高于商品销售金额'), (8, '退款后45天内未将商品退回'),
                             (9, '换货后45天内未将原商品退回'), (10, '换货但退款并发货'), (11, '换货超过30天未收重新入仓费'),
                             (12, '配送商品多于实际购买的商品'), (13, '尺寸重量错误而多收的物流费'), (14, '尺寸重量错误而多收的仓储费'),
                             (15, '尺寸重量错误而多收的合仓费'), (16, '入库时间错误而多收取仓库储存费'), (17, '未正确归类产品收取类目费错误'),
                             (18, '亚马逊从卖家订单退款中拿出部分金额安抚买家，而未赔偿给卖家'),
                             (19, '买家信用卡骗货行为'), (20, '退货显示已退回仓库实际上未退回'),
                             )

    process_status = ((0, '未处理'), (1, '处理中'), (2, '处理完成'))

    id = models.AutoField('id', primary_key=True)
    userid = models.IntegerField('用户id', blank=False, null=False)
    shop_name = models.CharField('店铺名', max_length=32, blank=True, null=True)
    site = models.CharField('站点', max_length=10,choices=site_choice, blank=True, null=True)
    seller_sku = models.CharField('店铺SKU', max_length=255, blank=True, null=True)
    seller = models.CharField('店长', max_length=255, blank=True, null=True)
    refund_type = models.SmallIntegerField('索赔类型',  choices=refund_type_selection, blank=True, null=True)
    amazon_order_id = models.CharField('订单编号', max_length=32, blank=True, null=True)
    shipment_id = models.CharField('发货编号', max_length=32, blank=True, null=True)
    fulfillment_fee_revise = models.DecimalField('修正后的尾程', max_digits=10,decimal_places=2, blank=True, null=True)
    refund_detail = models.CharField('索赔详情', max_length=1000, blank=True, null=True)
    deal_user = models.CharField('处理人', max_length=32, blank=True, null=True)
    deal_time = models.DateTimeField('处理时间', blank=True, null=True)
    deal_remark = models.CharField('处理备注', max_length=1000, blank=True, null=True)
    deal_status = models.SmallIntegerField('处理状态', choices=process_status, blank=True, null=True)
    case_id = models.CharField('索赔CASE ID', max_length=32, blank=True, null=True)
    update_case_id_datetime = models.DateTimeField('CASE ID填写时间', blank=True, null=True)
    refresh_time = models.DateTimeField('更新时间', blank=True, null=True)

    class Meta:
        verbose_name = u'AMZ-索赔统计-明细'
        verbose_name_plural = verbose_name
        db_table = 't_amazon_refund_statistics_detail'

    def __unicode__(self):
        return u'%s' % self.id


class StoreInfo(models.Model):
    """店铺授权信息模板"""

    store_status = (('1', '授权成功'), ('2', '授权中'), ('3', '授权失败'))

    id = models.AutoField('id', primary_key=True)
    userid = models.IntegerField('用户id', blank=False, null=False)
    shopname = models.CharField('店铺名称', max_length=100, blank=True, null=True)
    sellerid = models.CharField('SellerID', max_length=100, blank=False, null=False)
    token = models.CharField('Auth Token', max_length=100, blank=False, null=False)
    site = models.CharField('站点', max_length=10, choices=site_choice, blank=True, null=True)
    status = models.CharField('状态', max_length=2, choices=store_status, blank=True, null=True)
    authorizationd_datetime = models.DateTimeField('授权时间', blank=True, null=True)

    class Meta:
        verbose_name = u'店铺信息表'
        verbose_name_plural = verbose_name
        db_table = 'store_info'

    def __unicode__(self):
        return u'%s' % self.id


class AmazonFbaInventoryAdjustments(models.Model):
    """盘库"""
    reason_choice = (('1', '1-软件校正库存差额(+)'), ('2', '2-软件校正库存差额(-)'), ('3', '3-商品重新定义并从原始库存商品转入(+)'),
                     ('4', '4-商品重新定义并转出至新库存商品(-)'), ('5', '5-不可恢复的库存(-)'), ('6', '6-由入库承运人造成残损(-)'),
                     ('7', '7-过期商品残损(-)'), ('D', 'D-已销毁(-)'), ('E', 'E-在亚马逊运营中心残损(-)'),
                     ('F', 'F-已找到的库存(+)'), ('H', 'H-残损 – 买家退货(-)'), ('J', 'J-软件校正库存差额(+)'),
                     ('K', 'K-商品瑕疵造成的残损(-)'), ('M', 'M-误放库存(-)'), ('N', 'N-从暂存账户中转移(+)'),
                     ('O', 'O-转移至暂存账户(-)'), ('P', 'P-无法销售/无法配送库存(+)'), ('Q', 'Q-其他库存属性更改(-)'),
                     ('U', 'U-卖家造成的残损(-)'),)
    id = models.AutoField(primary_key=True)
    userid = models.IntegerField(u'用户id', blank=False, null=False)
    shop_name = models.CharField(u'店铺', max_length=32, blank=True, null=True)
    adjusted_date = models.DateTimeField(u'盘点日期', blank=True, null=True)
    transaction_item_id = models.CharField(u'交易商品编号', max_length=32, blank=True, null=True)
    fnsku = models.CharField(u'FNSKU', max_length=32, blank=True, null=True)
    sku = models.CharField(u'店铺SKU', max_length=255, blank=True, null=True)
    product_name = models.CharField(u'商品名称', max_length=255, blank=True, null=True)
    fulfillment_center_id = models.CharField(u'运营中心', max_length=32, blank=True, null=True)
    quantity = models.CharField(u'已盘点商品数量', max_length=16, blank=True, null=True)
    reason = models.CharField(u'盘点原因', choices=reason_choice, max_length=32, blank=True, null=True)
    disposition = models.CharField(u'库存属性', max_length=32, blank=True, null=True)
    refresh_time = models.DateTimeField(u'刷新时间', blank=True, null=True)

    class Meta:
        verbose_name = u'AMZ-FBA盘库'
        verbose_name_plural = verbose_name
        db_table = 't_amazon_fba_inventory_adjustments'

    def __unicode__(self):
        return u'%s' % self.shop_name


class AmazonFbaReimbursements(models.Model):
    # AMZ-FBA赔偿
    id = models.AutoField(primary_key=True)
    userid = models.IntegerField('用户id', blank=False, null=False)
    shop_name = models.CharField('店铺', max_length=32, blank=True, null=True)
    approval_date = models.DateTimeField('批准日期', blank=True, null=True)
    reimbursement_id = models.CharField('赔偿编号', max_length=32, blank=True, null=True)
    case_id = models.CharField('CASE编号', max_length=32, blank=True, null=True)
    amazon_order_id = models.CharField('亚马逊订单编号', max_length=32, blank=True, null=True)
    reason = models.CharField('原因', max_length=64, blank=True, null=True)
    sku = models.CharField('店铺SKU', max_length=255, blank=True, null=True)
    fnsku = models.CharField('FNSKU', max_length=32, blank=True, null=True)
    asin = models.CharField('ASIN', max_length=32, blank=True, null=True)
    product_name = models.CharField('商品名称', max_length=255, blank=True, null=True)
    # condition_ = models.CharField(u'商品状况', max_length=32, blank=True, null=True)
    currency_unit = models.CharField('货币单位', max_length=16, blank=True, null=True)
    amount_per_unit = models.CharField('每件商品的金额', max_length=16, blank=True, null=True)
    amount_total = models.CharField('总赔偿金额', max_length=16, blank=True, null=True)
    quantity_reimbursed_cash = models.CharField('现金赔偿商品量', max_length=8, blank=True, null=True)
    quantity_reimbursed_inventory = models.CharField('库存赔偿商品量', max_length=8, blank=True, null=True)
    quantity_reimbursed_total = models.CharField('赔偿商品总量', max_length=8, blank=True, null=True)
    original_reimbursement_id = models.CharField('原始赔偿编号', max_length=32, blank=True, null=True)
    original_reimbursement_type = models.CharField('原始赔偿类型', max_length=32, blank=True, null=True)
    refresh_time = models.DateTimeField('刷新时间', blank=True, null=True)

    class Meta:
        verbose_name = u'AMZ-FBA赔偿'
        verbose_name_plural = verbose_name
        db_table = 't_amazon_fba_reimbursements'

    def __unicode__(self):
        return u'%s' % self.shop_name


class Summary(models.Model):
    id = models.IntegerField(primary_key=True)
    userid = models.IntegerField(blank=False, null=False)
    damaged_lost = models.IntegerField('损坏丢失', default=0)
    delivery_acceptance_diff = models.IntegerField('发货接收差异', default=0)
    refund_not_returned = models.IntegerField('退款未退货', default=0)
    exchange_not_returned = models.IntegerField('换货未退款', default=0)
    exchange_and_refund = models.IntegerField('换货且退款', default=0)
    overcharge_shipping = models.IntegerField('多收运费', default=0)
    overcharge_storage_fees = models.IntegerField('多收存储费', default=0)
    total_num = models.IntegerField('汇总', default=0)
    other = models.IntegerField('其它', default=0)
    authorize_success = models.IntegerField('授权成功', default=0)
    authorize_ing = models.IntegerField('授权中', default=0)
    authorize_failed = models.IntegerField('授权失败', default=0)

    class Meta:
        verbose_name = '数据汇总'
        db_table = 't_summary'

    def __str__(self):
        return '%s' % self.use


class EveryDayIncome(models.Model):
    id = models.AutoField(primary_key=True)
    userid = models.IntegerField('用户id', blank=False, null=False)
    day_income = models.DecimalField('每日收入', max_digits=13, decimal_places=2, default=0.00)
    yy = models.CharField('年', max_length=10, blank=True, null=True)
    mm = models.CharField('月', max_length=10, blank=True, null=True)
    dd = models.CharField('日', max_length=10, blank=True, null=True)

    class Meta:
        verbose_name = '每日收入'
        db_table = 'every_day_income'

    def __str__(self):
        return '%s' % self.userid